<template>
  <div class="home">
    <Search :mess="mess" />
    <van-tabs title-active-color="red">
      <van-tab v-for="(item, index) in title" :title="item" :key="index">
        <div id="title">
          <div
            class="title-item"
            v-for="(item, index) in titleList"
            :key="index"
          >
            <img :src="item.imgsrc" alt="" />
            <p>{{ item.text }}</p>
          </div>
        </div>
        <div class="nav">
          <div class="left">
            <img
              src="https://funimg.pddpic.com/brand_creation/b974124a-faaa-4c95-b074-e9c4eb6c9e31.png?imageView2/2/w/78/q/80/format/webp"
              alt=""
            />
            <p class="left-title">百亿补贴</p>
            <p class="left-text">大牌正品</p>
          </div>
          <div class="img">
            <img
              src="https://funimg.pddpic.com/recone/2020-09-10/ea56b47f-2ec2-4c95-9e8b-87d9ccc1cfc0.png?imageView2/2/w/1300/q/80/format/webp"
              alt=""
            />
          </div>
          <div class="right">
            <div class="right-item" v-for="(item, index) in nav" :key="index">
              <img :src="item.imgsrc" alt="" />
              <p>¥{{ item.price }}</p>
            </div>
          </div>
        </div>
        <div class="list">
          <div class="list-item" v-for="(item, index) in list" :key="index">
            <img :src="item.imgsrc" alt="" />
            <div class="detail">
              <p class="title">{{ item.title }}</p>
              <p class="num-box">
                <span class="num">立减{{ item.num }}元</span>
                <span class="con">退货包运费</span>
              </p>
              <div class="price-box">
                <span class="price">券后¥{{ item.price }}</span>
                <span class="count">已拼{{ item.count }}万件</span>
              </div>
            </div>
          </div>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>

<script>
// @ is an alias to /src
import instance from "../api/api";
import Search from "../components/Search.vue";
export default {
  name: "HomeView",
  data() {
    return {
      mess: "高效学习方法",
      title: ["推荐", "女装", "鞋包", "手机", "食品", "母婴", "男装", "百货"],
      titleList: [],
      nav: [],
      list: [],
    };
  },
  components: {
    Search,
  },
  methods: {
    async getData() {
      let { data } = await instance("/api");
      console.log(data);
      this.titleList = data.title;
      this.nav = data.nav;
      this.list = data.list;
    },
  },
  created() {
    this.getData();
  },
};
</script>
<style lang="less" scoped>
.home {
  width: 375px;
}
#title {
  // width: 450px;
  height: 120px;
  overflow: hidden;
  border-top: 1px solid #eee;
  padding: 5px 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  overflow: scroll;
  .title-item {
    width: 73px;
    height: 60px;
    text-align: center;
    margin-bottom: 10px;
    img {
      width: 40px;
      height: 40px;
    }
    p {
      color: #666;
      font-size: 12px;
      margin-top: 5px;
    }
  }
}

#title::-webkit-scrollbar {
  display: none;
}
.nav {
  width: 375px;
  box-sizing: border-box;
  margin-top: 8px;
  padding: 0 12px 0 8px;
  text-align: center;
  display: flex;
  .left {
    width: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    img {
      width: 40px;
      height: 40px;
    }
    .left-title {
      color: #151516;
      font-size: 12px;
      margin-bottom: 7px;
    }
    .left-text {
      color: #777;
      font-size: 12px;
    }
  }
  .img {
    width: 6px;
    height: 82px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .right {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 5px;
    img {
      width: 64px;
      height: 64px;
    }
    p {
      color: #e02e24;
      font-size: 14px;
    }
  }
}
.list {
  width: 375px;
  padding: 7px;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  .list-item {
    width: 177px;
    img {
      width: 177px;
      height: 177px;
    }
    .detail {
      width: 100%;
      padding: 8px 8px 10px;
      box-sizing: border-box;
      .title {
        color: #151516;
        font-size: 14px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        line-height: 18px;
        font-weight: 400;
      }
      .num-box {
        width: 100%;
        display: flex;
        .num {
          color: #e02e24;
          font-size: 12px;
          margin-right: 10px;
        }
        .con {
          color: #777;
          font-size: 12px;
        }
      }
      .price-box {
        margin-top: 12px;
        width: 100%;
        display: flex;
        align-items: center;
        .price {
          color: #e02e24;
          font-weight: 400;
          font-size: 13px;
          margin-right: 10px;
        }
        .count {
          font-size: 13px;
          color: #939393;
        }
      }
    }
  }
}
</style>
